/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.itver.uml.dataobject;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.netbeans.core.spi.multiview.MultiViewElement;
import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObjectExistsException;
import org.openide.loaders.MultiDataObject;
import org.openide.loaders.MultiFileLoader;
import org.openide.nodes.Node;
import org.openide.util.Lookup;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.TopComponent;

public class ItverUMLDataObject extends MultiDataObject {

    private ItverData data;
    
    public ItverUMLDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
        super(pf, loader);
        registerEditor("text/x-itver_uml", true);
        
        InputStream input = pf.getInputStream();
        Properties props = new Properties();
        props.load( input );
        input.close();

        data = new ItverData( props );
    }
    
    @Override
    protected Node createNodeDelegate() {
//        return new DataNode(this, Children.LEAF, getLookup());
        return new NodeItverData(this, data);
    }
    
    @Override
    protected int associateLookup() {
        return 1;
    }

    @MultiViewElement.Registration(displayName = "#LBL_ItverUML_EDITOR",
    iconBase = "org/itver/uml/dataobject/uml-project.png",
    mimeType = "text/x-itver_uml",
    persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
    preferredID = "ItverUML",
    position = 1000)
    @Messages("LBL_ItverUML_EDITOR=Source")
    public static MultiViewEditorElement createEditor(Lookup lkp) {
        return new MultiViewEditorElement(lkp);
    }
}
